//
//  WYBusinessSearchController.m
//  Boss
//
//  Created by admin on 2018/9/12.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYBusinessSearchController.h"
#import "CJTopLineOneCell.h"
#import "CJTopLineThreeCell.h"
#import "CJTopLineBigCell.h"
#import "CJBOSSRecommendCell.h"
#import "CJStictSaleCell.h"
@interface WYBusinessSearchController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSArray *sectionNameArray;
@end

@implementation WYBusinessSearchController
-(NSArray *)sectionNameArray
{
    if (!_sectionNameArray) {
        _sectionNameArray = @[@"品牌加盟",@"渠道销售",@"BOSS头条"];
    }
    return _sectionNameArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //self.navigationItem.leftBarButtonItem = nil;
    
    [self setupUI];
    // Do any additional setup after loading the view.
}
-(void)setupUI
{
    self.navigationItem.hidesBackButton = YES;
    UITextField *textField = [[UITextField alloc]init];
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.frame = CGRectMake(32, 7, kScreenWidth-64, 30);
    self.navigationItem.titleView = textField;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:(UIBarButtonItemStyleDone) target:self action:@selector(cancelAction:)];
    textField.text = self.searchTitle;
    
    [self.view addSubview:self.tableView];
    self.tableView.estimatedRowHeight = 100;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"CJTopLineOneCell" bundle:nil] forCellReuseIdentifier:@"CJTopLineOneCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"CJTopLineThreeCell" bundle:nil] forCellReuseIdentifier:@"CJTopLineThreeCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"CJTopLineBigCell" bundle:nil] forCellReuseIdentifier:@"CJTopLineBigCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"CJBOSSRecommendCell" bundle:nil] forCellReuseIdentifier:@"CJBOSSRecommendCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"CJStictSaleCell" bundle:nil] forCellReuseIdentifier:@"CJStictSaleCell"];
    
    
    
    
    
}
-(void)cancelAction:(UIBarButtonItem *)item
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        CJBOSSRecommendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CJBOSSRecommendCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[NSBundle mainBundle] loadNibNamed:@"CJBOSSRecommendCell" owner:nil options:nil].firstObject;
        }
        return cell;
        
    }
    if (indexPath.section==1) {
        
        CJStictSaleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CJStictSaleCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[NSBundle mainBundle]loadNibNamed:@"CJStictSaleCell" owner:nil options:nil].firstObject;
        }
        return cell;
        
    }
    
    if (indexPath.section==2) {
        CJTopLineThreeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CJTopLineThreeCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[NSBundle mainBundle]loadNibNamed:@"CJTopLineThreeCell" owner:nil options:nil].firstObject;
        }
        return cell;
    }
    
    
    
    
    return nil;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc]init];
    label.text = self.sectionNameArray[section];
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(view);
    }];
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc]init];
    label.text = @"查看更多品牌加盟";
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.equalTo(view).offset(5);
    }];
    
    UIImageView *rightImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"right"]];
    [view addSubview:rightImageView];
    
    [rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.equalTo(view).offset(5);
    }];
    
    UIView *lineView = [[UIView alloc]init];
    [view addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(5);
    }];
    lineView.backgroundColor = [UIColor hexStringToColor:@"#f7f7f7" alpha:1.0];
    
    
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 50;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UITableView *)tableView
{
    if (_tableView == nil) {
        CGRect frame = CGRectMake(0, self.navHeight, kScreenWidth, kScreenHeight-self.navHeight);
        _tableView = [[UITableView alloc] initWithFrame:frame
                                                  style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
    }
    return _tableView;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
